package m3;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.Scanner;
import java.util.concurrent.TimeoutException;

public class Producer {

    public static void main(String[] args) throws IOException, TimeoutException {

        //连接
       ConnectionFactory f= new ConnectionFactory();
       //f.setHost("192.168.64.140");
        f.setHost("wht6.cn");
       f.setUsername("admin");
       f.setPassword("admin");

       Channel c=f.newConnection().createChannel();
       //创建Fanout类型交换机，命名为logs
         c.exchangeDeclare("logs", "fanout");

        //向交换机发送消息
        while (true){
            System.out.println("输入消息：");



       //  String s=new Scanner(System.in).nextLine();
            String s="大家好";
         //对于fanout交换机,第二个参数无效,不会发送到写的队列，而是发送到交换机
            c.basicPublish("logs","",null,s.getBytes());

        }
    }
}
